package com.wu.creditmanager.util;

import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.adview.AdViewLayout;
import com.wu.creditmanager.R;

public class LayoutUtil {

	public static void initToolbar(final Activity activity, String titleResId,
			OnClickListener btn1ClickListener, String btn2TextResId,
			OnClickListener btn2ClickListener) {
		View tbar = activity.findViewById(R.id.tbar);
		TextView title = (TextView) tbar.findViewById(R.id.tbar_textview);
		title.setText(titleResId);
		Button button1 = (Button) tbar.findViewById(R.id.tbar_btn1);
		if (btn1ClickListener == null) {
			btn1ClickListener = new OnClickListener() {
				public void onClick(View v) {
					activity.setResult(Activity.RESULT_CANCELED);
					activity.finish();
				}
			};
		}
		button1.setOnClickListener(btn1ClickListener);
		Button button2 = (Button) tbar.findViewById(R.id.tbar_btn2);
		button2.setText(btn2TextResId);
		button2.setOnClickListener(btn2ClickListener);
	}

	public static void initAdLayout(Activity activity) {
		LinearLayout layout = (LinearLayout) activity
				.findViewById(R.id.adLayout);
		AdViewLayout adViewLayout = new AdViewLayout(activity,
				Constants.ADVIEWKEY);
		layout.addView(adViewLayout);
		layout.invalidate();
	}

	public static void initToolbar(Activity activity, int titleResId,
			OnClickListener btn1ClickListener, int btn2TextResId,
			OnClickListener btn2ClickListener) {
		initToolbar(activity, activity.getResources().getString(titleResId),
				btn1ClickListener,
				activity.getResources().getString(btn2TextResId),
				btn2ClickListener);
	}
}
